#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Mikan 開発用 パッケージ

Mikan Python Web Framework
"""

__author__ = "K.Sonohara"
__status__ = "develop"
__version__ = "0.0.0_36"
__date__    = "2014/01/05"
__license__ = 'LGPL'

# ------------------------------------------------------------
## インポート
# ------------------------------------------------------------
# Python
import traceback

# ESiPC
from esipc import ESiPCProperty

# Mikan
from mikan.db import AbstractMikanItemDatabase

# ------------------------------------------------------------
## 変数
# ------------------------------------------------------------

# ------------------------------------------------------------
## 関数
# ------------------------------------------------------------

# ------------------------------------------------------------
## クラス
# ------------------------------------------------------------
class AbstractMikanORM(AbstractMikanItemDatabase):

	def __init__(self, request):
		# super
		super(AbstractMikanORM, self).__init__(request)

	def connect(self):
		pass

	def close(self):
		pass

	def commit(self):
		pass

	def rollback(self):
		pass

	def get_orm_version(self):
		return ""

	def get_orm_name(self):
		return ""

	def get_version(self):
		return self.get_orm_version()

	def get_name(self):
		return self.get_orm_name()

# ------------------------------------------------------------
## Mikan DB抽象 クラス
#
def new_mikan_orm(request, dbtype="sqlalchemy"):
		t = None

		if (dbtype == "sqlalchemy"):
			t = "MikanSQLAlchemyORM"

		if request and request.islogdebug:
			request.logger.debug(t)

		try:
			module = "mikan.orm." + dbtype + "orm"
			fromlist = [module]
			module = __import__(module, fromlist=fromlist)

			c = getattr(module, t)
			if request and request.islogdebug:
				request.logger.debug(c)
			return c(request)
		except:
			if request:
				request.logger.error(module)
				request.logger.error([module])
				request.logger.error(traceback.format_exc())
			else:
				print traceback.format_exc()

		return None

# ------------------------------------------------------------
## メイン関数
# ------------------------------------------------------------
if __name__ == '__main__':
	pass

# ------------------------------------------------------------
